package com.hspedu.Homework;

import java.io.*;
import java.util.Properties;

/**
 * @author DL5O
 * @version 1.0
 */
public class Homework03 {
    public static void main(String[] args) throws IOException {
        //编写dog.properties
        String filePath = "src\\dog.properties";
        Properties properties = new Properties();
        properties.setProperty("name","tom");
        properties.setProperty("age","5");
        properties.setProperty("color","red");
        //保存~
        properties.store(new FileWriter(filePath),null);
        System.out.println("保存成功~~");

        //读取dog.properties
        String name = properties.getProperty("name");
        int age = Integer.parseInt(properties.getProperty("age"));
        String color = properties.getProperty("color");
        //完成dog的初始化
        Dog dog = new Dog(name,age,color);
        System.out.println(dog);

        //进行序列化
        String storePath = "D:\\dog.dat";
        ObjectOutputStream oos= new ObjectOutputStream(new FileOutputStream(storePath));
        oos.writeObject(dog);
        System.out.println("序列化成功~~");
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream(storePath));
        try {
            Dog o = (Dog)ois.readObject();
            System.out.println("=====反序列化=====");
            System.out.println(o);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}

